/*
 * @Author: jingfuu@163.com
 * @Date: 2024-12-16 13:21:09
 * @LastEditTime: 2024-12-16 14:36:05
 * @Description: file content
 */
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import ExamPlanService from '../service/ExamPlanService';
import ExamPlanQueryParam from '../param/ExamPlanQueryParam';
import ExamPlanVo from '../vo/ExamPlanVo';
import { R } from 'src/common/R';
import BusinessType from 'src/common/enum/BusinessType';
import { Log } from 'src/common/decorator/LogDecorator';
import ExamPlanDto from '../dto/ExamPlanDto';

/*
 * @Author: jingfuu@163.com
 * @Date: 2024-12-16 13:21:09
 * @LastEditTime: 2024-12-16 13:52:09
 * @Description: 考试计划接口
 */
@Controller('exam/plan')
@ApiTags('考试计划接口')
class ExamPlanController {
  constructor(private examPlanService: ExamPlanService) {}

  @ApiOperation({ summary: '获取考试计划列表' })
  @Get('list')
  async list(@Query() param: ExamPlanQueryParam): Promise<R<ExamPlanVo>> {
    return R.page(await this.examPlanService.list(param));
  }

  @ApiOperation({ summary: '获取考试计划详情' })
  @Get(':id(\\d+)')
  async findDetail(@Param('id') id: number): Promise<R<ExamPlanVo>> {
    return R.ok(await this.examPlanService.detail(id));
  }

  @ApiOperation({ summary: '新增考试计划' })
  @Log({
    title: '考试计划',
    businessType: BusinessType.INSERT,
  })
  @Post()
  async add(@Body() data: ExamPlanDto): Promise<R<void>> {
    await this.examPlanService.add(data);
    return R.ok();
  }

  @ApiOperation({ summary: '修改考试计划' })
  @Log({
    title: '考试计划',
    businessType: BusinessType.UPDATE,
  })
  @Put()
  async modifyExamDistrict(@Body() data: ExamPlanDto): Promise<R<void>> {
    await this.examPlanService.edit(data);
    return R.ok();
  }

  @ApiOperation({ summary: '删除考试计划' })
  @Log({
    title: '考试计划',
    businessType: BusinessType.DELETE,
  })
  @Delete('/:id')
  async remove(@Param('id') id: string): Promise<R<any>> {
    if (id.indexOf(',') > -1) {
      for (const item of id.split(',')) {
        await this.examPlanService.remove(Number.parseInt(item));
      }
    } else {
      await this.examPlanService.remove(Number.parseInt(id));
    }
    return R.ok();
  }
}
export default ExamPlanController;
